<template>
  <page-wrap ref="pageWrap" hideTab back title="一览通" navLeft :showTop="false" :dark="loaded? false: true" hideSafeArea>

    <!-- 已开通 -->
    <view class="vip-detail" :class="'vip-'+(vipLevel)">
      <view class="top">
        <view class="card-wrap" :class="['card-'+ vipLevel]">
          <view class="box">
            <image :src="circleImg" mode="widthFix" class="circle"></image>
            <text class="icon icon-current"></text>
            <view class="user-info">
              <view class="avatar-wrap">
                <image :src="personInfo.headImg" class="avatar" mode="widthFix"></image>
              </view>
              <view class="user-info-right">
                <image class="icon icon-title" :src="versionInfo.versionNameImg"></image>
                <view class="user-name">{{personInfo.iname}}</view>
              </view>
            </view>
            <view class="label">
              <template>剩余账号：{{personInfo.leftAccountNum}}个</template>
            </view>

            <text class="icon icon-diamonds"></text>
          </view>
        </view>
      </view>
      <template>
        <scroll-view scroll-y class="scroll-view">
          <view v-for="item,index in rightsSubAccount" :key="index">
            <view class="space"></view>
            <view class="rightsSubAccountItem" v-if="item.isActive==1">
              <view class="subAccountInfo">
                <image :src="item.headImg" class="personAvatar"></image>
                <view class="subAccountInfoDetail">
                  <view class="subAccountName">{{item.iname}}</view>
                  <view class="activiTime">激活时间：{{item.activiTime}}</view>
                </view>
              </view>
              <view class="subAccountRights">
                <span class="useReportNum">已使用报告：{{item.useReportNum}}份</span>
                <span class="useCaseNum">已使用案例：{{item.useCaseNum}}份</span>
              </view>
              <image :src="activatedIcon" class="activatedIcon"></image>
            </view>
            <view class="codeItem" v-else>
              <span class="code">激活码：{{item.inviteCode}}</span>
              <view class="copyButton" @click="handleCopyClick(item.inviteCode)"><span>复制</span></view>
            </view>
          </view>
        </scroll-view>
      </template>
      <view class="guide" @click="handleToGuide">
        怎么激活子账号？查看操作指南 >
      </view>
    </view>
  </page-wrap>
</template>

<script>
import { personRightsAccountList } from "@/api/modules/vip";
import ShareMixin from "@/mixins/share";

export default {
  mixins: [ShareMixin],
  data() {
    return {
      personId: uni.getStorageSync("person-id").slice(2) || undefined,
      companyId: uni.getStorageSync("company-id"),
      topHeight: getApp().globalData.topHeight,
      vipLevel: 0,
      currentVipLevel: 0,
      personInfo: {},
      versionInfo: {},
      circleImg: this.$imgBaseSelf + "vip/circle.png",
      activatedIcon:
        "https://upload.yl1001.com/upload/images/view?file=b0cv2ODilbBcMdEqlasgWAt0k-/JVcbiCU8zab1OlbFQLphi,7XOF/-5qxjia.png",
      loaded: false,
      shareTitle: "一览通，企业成长顾问",
      sharePath: "/pagesSub/companyCenter/vip/index",
      item: {},
      rightsSubAccount: [],
    };
  },
  created() {},
  mounted() {
    this.getData();
  },
  onLoad(opt) {},
  methods: {
    handleToGuide() {
      uni.showLoading({
        title: "打开中",
      });
      const fileUrl =
        "https://img3.job1001.com/ylt/一览通共享权益账号开通指南.pdf";
      uni.downloadFile({
        url: fileUrl, // 文件的本身url
        filePath: wx.env.USER_DATA_PATH + "/一览通共享权益账号开通指南.pdf", // 本地自定义的文件名
        success: function (res) {
          let filePath = res.filePath;
          uni.openDocument({
            filePath: filePath,
            success: function () {
              uni.hideLoading();
            },
            fail: function () {
              uni.hideLoading();
            },
          });
          uni.hideLoading();
        },
        fail: function (res) {
          uni.hideLoading();
          uni.showToast({
            title: "下载文件失败！",
            icon: "error",
          });
        },
        complete: (res) => {
          console.log("complete", res);
        },
      });
    },
    getData() {
      const params = {
        // personId: 0,
        personId: this.personId || 0,
        companyId: this.personId || 0,
        tradeVersionRightsId: 123,
        rightsType: "public",
      };
      uni.showLoading();
      personRightsAccountList(params)
        .then((res) => {
          if (res.code == 200) {
            this.current = 0;
            this.personInfo = res.data.personInfo;
            this.versionInfo = res.data.versionInfo;
            this.vipLevel = res.data.personInfo.yltLevel || 3;
            this.rightsSubAccount = res.data.rightsSubAccount;
            this.setNavigationBar();
            this.loaded = true;
          } else {
            uni.showToast({
              title: res.status_desc,
              icon: "none",
            });
          }
        })
        .finally(() => {
          uni.hideLoading();
        });
    },
    handleCopyClick(val) {
      uni.setClipboardData({
        data: val,
        success: () => {
          uni.showToast({ title: "复制成功" });
        },
        fail: () => {
          uni.showToast({ title: "复制失败" });
        },
      });
    },
    setNavigationBar() {
      uni.setNavigationBarColor({
        frontColor: "#ffffff",
        backgroundColor: "",
      });
    },
    change(e) {
      this.current = e.detail.current;
    },
    needToLogin() {
      this.$refs.pageWrap.handleLogin();
    },
  },
};
</script>

<style lang="scss" scoped>
.vip {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  background-image: url($img-base + "ecenter/my-vip-sm.png");
  background-color: #000960;
  background-size: 100%;
  background-repeat: no-repeat;
  // padding-bottom: calc(150rpx + constant(safe-area-inset-bottom));
  // padding-bottom: calc(150rpx + env(safe-area-inset-bottom));

  .top {
    position: sticky;
    top: 0;
    z-index: 10;
    height: 412rpx;
    // background: url($img-base + 'ecenter/vip-m-top-bg.png');
    // background-size: 100%;
    overflow: hidden;

    .top-img {
      position: absolute;
      width: 100%;
      height: 216rpx;
      bottom: 0;
      left: 0;
    }
  }

  .img-w {
    width: 100%;
  }
  .img-code {
    width: 210rpx;
  }
  .img-open {
    width: 458rpx;
  }

  .price {
    display: flex;
    margin: 48rpx 0 4rpx 0;
    padding: 0 32rpx;
    justify-content: space-around;
    .img-price {
      margin-left: 34rpx;
      &:nth-child(1) {
        margin: 0;
      }
    }
  }

  .scroll-view {
    // height: 1px;
    padding: 0 32rpx;
    flex-grow: 1;
    view:last-child {
      padding-bottom: calc(150rpx + constant(safe-area-inset-bottom));
      padding-bottom: calc(150rpx + env(safe-area-inset-bottom));
    }
  }

  .buy {
    position: fixed;
    // bottom: calc(constant(safe-area-inset-bottom));
    // bottom: calc(env(safe-area-inset-bottom));
    bottom: 0;
    // height: 162rpx;
    .container {
      background-size: 100% 150%;
      .noPayButtons {
        display: flex;
        justify-content: space-between;
        // align-items: center;
        padding: 0 34rpx;
        width: 100%;
      }
      .protocolTips {
        margin-top: 14rpx;
        text-align: center;
        color: #b4dcff;
        span {
          color: #a9a49e;
        }
      }
    }

    .colorBlock {
      width: 100%;
      // height: calc(constant(safe-area-inset-bottom));
      // height: calc(env(safe-area-inset-bottom));
      // background-color: #000960;
      height: 68rpx;
    }
  }

  &.vip-2 {
    background-image: url($img-base + "vip/my-vip-sm.png");
    background-color: #0c0116;
  }

  &.vip-3 {
    background-image: url($img-base + "vip/my-vip-md.png");
    background-color: #0c0116;
  }

  &.vip-4 {
    background-image: url($img-base + "vip/my-vip-high.png");
    background-color: #0c0116;
  }
}

.slot-content {
  // height: 300rpx;
  padding: 0 32rpx;
}

view[hidden] {
  display: none !important;
}

// 详情页
.vip-detail {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  background-color: #000960;
  padding-bottom: calc(calc(80rpx + constant(safe-area-inset-bottom)));
  padding-bottom: calc(calc(80rpx + env(safe-area-inset-bottom)));
  .top {
    position: relative;
    height: 474rpx;
    // background-image: url($img-base + 'ecenter/vip-samll-top-bg.png');
    background-size: 100% 100%;
    .card-wrap {
      position: relative;
      top: 69%;
      left: 50%;
      transform: translate(-50%, -50%);
      padding: 0 32rpx;
      .icon-diamonds {
        position: absolute;
        bottom: 0rpx;
        right: -24rpx;
        width: 312rpx;
        height: 310rpx;
        pointer-events: none;
      }

      &.card-1 {
        .box {
          background-image: url($img-base + "vip/card-bg-sm.png");
        }

        .icon-current {
          background-image: url($img-base + "vip/curren-level-sm.png");
        }

        .icon-title {
          margin-bottom: 12rpx;
          width: 186rpx;
          height: 50rpx;
        }

        .icon-diamonds {
          background-image: url($img-base + "vip/diamonds-sm.png?v=1");
        }

        .icon-action {
          background-image: url($img-base + "vip/update-sm.png");
        }
      }

      &.card-2 {
        .box {
          background-image: url($img-base + "vip/card-bg-sm.png");
        }

        .icon-current {
          background-image: url($img-base + "vip/curren-level-sm.png");
        }

        .icon-diamonds {
          background-image: url($img-base + "vip/diamonds-sm.png?v=1");
        }

        .icon-action {
          background-image: url($img-base + "vip/update-2.png");
        }
      }

      &.card-3 {
        .box {
          background-image: url($img-base + "vip/card-bg-md.png");
        }

        .icon-current {
          background-image: url($img-base + "vip/curren-level-md.png");
        }

        .icon-diamonds {
          right: -14rpx;
          background-image: url($img-base + "vip/diamonds-md.png?v=1");
        }

        .icon-action {
          background-image: url($img-base + "vip/update-md.png");
        }

        .label {
          color: #835ace;
        }

        .user-name {
          color: #a315a9 !important;
        }
      }

      &.card-4 {
        .box {
          background-image: url($img-base + "vip/card-bg-high.png");
        }

        .icon-current {
          background-image: url($img-base + "vip/curren-level-high.png");
        }

        .icon-diamonds {
          bottom: 20rpx;
          right: -10rpx;
          background-image: url($img-base + "vip/diamonds-h.png");
        }

        .icon-action {
          background-image: url($img-base + "vip/update-high.png");
        }

        .label {
          color: #8c8c8b;
        }

        .user-name {
          color: #ffea9f !important;
        }
      }

      &.not-current {
        .icon-title {
          position: absolute;
          top: 52rpx;
          left: 30rpx;
        }

        &.card-2 {
          .icon-action {
            background-image: url($img-base + "vip/buy-sm.png");
          }
        }

        &.card-3 {
          .icon-action {
            background-image: url($img-base + "vip/buy-md.png");
          }
        }

        &.card-4 {
          .icon-action {
            background-image: url($img-base + "vip/buy-high.png");
          }
        }
      }
    }

    .box {
      position: relative;
      // width: 604rpx;
      height: 274rpx;
      background-size: 100% 100%;

      .icon-current {
        margin: 4rpx 0 0 2rpx;
        width: 186rpx;
        height: 50rpx;
      }

      .icon-title {
        margin-bottom: 4rpx;
        width: 160rpx;
        height: 48rpx;
      }

      .icon-action {
        position: absolute;
        bottom: 28rpx;
        right: 40rpx;
        width: 164rpx;
        height: 60rpx;
      }

      .circle {
        position: absolute;
        right: 0;
        bottom: 0;
        width: 338rpx;
        height: 274rpx;
        z-index: 1;
        pointer-events: none;
      }

      .user-info {
        display: flex;
        align-items: center;
        margin: 22rpx 0 32rpx 28rpx;
        height: 100rpx;

        .avatar-wrap {
          display: inline-block;
          flex-shrink: 0;
          width: 72rpx;
          height: 72rpx;
          margin-right: 14rpx;
          padding: 2rpx;
          background: linear-gradient(to bottom, #dbf1f5 100%, #caf0f9 100%);
          border-radius: 50%;
        }

        .avatar {
          width: 68rpx;
          height: 68rpx;
          border-radius: 50%;
        }

        .user-name {
          font-size: $uni-font-size-base;
          font-weight: bold;
          color: #ffffff;
        }
      }

      .label {
        position: absolute;
        bottom: 34rpx;
        left: 0;
        z-index: 2;
        margin-left: 36rpx;
        font-size: $uni-font-size-sm;
        color: #bdd4ff;
      }
    }
  }

  .scroll-view {
    // height: 1px;
    // height: calc(100vh - 474rpx);
    // flex-grow: 1;
    width: calc(100vw - 64rpx);
    padding: 0 32rpx;
    .space {
      height: 24rpx;
    }

    .box:last-child {
      padding-bottom: calc(150rpx + constant(safe-area-inset-bottom));
      padding-bottom: calc(150rpx + env(safe-area-inset-bottom));
    }

    .rightsSubAccountItem {
      position: relative;
      // height: 212rpx;
      background: #ffffff;
      border-radius: 16rpx;
      padding: 20rpx 28rpx;
      .subAccountInfo {
        display: flex;
        height: 110rpx;
        padding-bottom: 24rpx;
        .personAvatar {
          width: 60rpx;
          height: 60rpx;
          border-radius: 50%;
          margin-right: 28rpx;
          margin-top: 13rpx;
        }
        .subAccountInfoDetail {
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          .subAccountName {
            font-size: 32rpx;
            font-family: PingFang-SC-Bold, PingFang-SC;
            font-weight: bold;
            color: #222222;
            line-height: 44rpx;
          }
          .activiTime {
            font-size: 24rpx;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #888888;
            line-height: 34rpx;
          }
        }
      }
      .subAccountRights {
        border-top: 1px solid #ccc;
        height: 56rpx;
        padding-top: 20rpx;
        margin-bottom: 2rpx;
        span {
          width: 188rpx;
          font-size: 24rpx;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #555555;
          // line-height: 34rpx;
        }
        .useReportNum {
          margin-right: 64rpx;
        }
      }
      .activatedIcon {
        position: absolute;
        top: 0;
        right: 0;
        width: 116rpx;
        height: 48rpx;
      }
    }
    .codeItem {
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 96rpx;
      padding: 0 38rpx;
      background-color: #ffffff;
      border-radius: 16rpx;
      .code {
        color: #f75a3e;
      }
      .copyButton {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 128rpx;
        height: 64rpx;
        background: #f75a3e;
        border-radius: 12rpx;
        outline: none;
        color: white;
        font-size: 32rpx;
        text-align: center;
      }
    }
  }

  .img-w {
    width: 100%;
  }

  .buy {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(-10rpx + constant(safe-area-inset-bottom));
    bottom: calc(-10rpx + env(safe-area-inset-bottom));
  }

  &.vip-1 {
    background-image: url($img-base + "vip/my-vip-sm.png");
    background-size: 100%;
  }

  &.vip-2 {
    background-image: url($img-base + "vip/my-vip-sm.png");
    background-size: 100%;
  }

  &.vip-3 {
    background-image: url($img-base + "vip/my-vip-md.png");
    background-size: 100%;
  }

  &.vip-4 {
    background-image: url($img-base + "vip/my-vip-high.png");
    background-size: 100%;
  }
}
.guide {
  text-align: center;
  font-size: 28rpx;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #bcb192;
  line-height: 40rpx;
  margin-top: 64rpx;
}
::v-deep
  .page-wrap
  .content-wrap
  .u-form
  .u-form-item
  .u-form-item--left__content__label {
  margin-bottom: 0;
}
</style>